package com.room.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyh.dao.SysConstant;
import com.cyh.dao.dto.SolicitDmtDto;
import com.cyh.dao.dto.SolicitNewDto;
import com.cyh.dao.entity.SolicitDmt;
import com.cyh.dao.entity.SolicitNew;
import com.cyh.dao.entity.SysUser;
import com.cyh.dao.mapper.SolicitDmtMapper;
import com.cyh.dao.mapper.SolicitNewMapper;
import com.cyh.dao.mapper.SysUserMapper;
import com.room.core.dto.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserService  extends ServiceImpl<SysUserMapper, SysUser> {

    @Autowired
    private SolicitDmtService solicitDmtService;

    @Autowired
    private SolicitDmtMapper solicitDmtMapper;

    @Autowired
    private SolicitNewMapper solicitNewMapper;

    @Autowired
    private SolicitNewService solicitNewService;

    public List<SysUser> getRankList() {
        List<SysUser> list = this.list(new LambdaQueryWrapper<SysUser>()
                .select(SysUser::getNickName, SysUser::getAvatarUrl, SysUser::getLearnLen));
        return list;
    }

    public Map<String, Object> getSolicitrRecord(UserInfo userInfo) {
        Map<String, Object> map = new HashMap<>();

        List<SolicitDmtDto> dmtList = solicitDmtMapper.getSolicitDmtByMyList(userInfo.getId());
        for (SolicitDmtDto item : dmtList) {
            item.setAgreeIsFormat(SysConstant.getValue("agreeIs", item.getAgreeIs()));
        }

        List<SolicitNewDto> newList = solicitNewMapper.getSolicitNewByMyList(userInfo.getId());
        for (SolicitNewDto item : newList) {
            item.setAgreeIsFormat(SysConstant.getValue("agreeIs", item.getAgreeIs()));
        }
        map.put("dmtList",dmtList);
        map.put("newList",newList);
        return map;
    }
}
